package net.bac.sbe.web.sonar.server;

import java.util.ArrayList;
import java.util.List;

import net.bac.sbe.svn.SVNBrowser;
import net.bac.sbe.svn.exception.SbeSvnException;
import net.bac.sbe.svn.view.SbeSVNDiffItemView;
import net.bac.sbe.web.sonar.server.dev.utils.xml.applications.ApplicationsConfig;

import com.google.inject.Inject;

public class SVNServiceWrapperImpl implements SVNServiceWrapper {

	@Inject
	private SVNBrowser svnBrowser;

	public void setSvnBrowser(SVNBrowser svnBrowser) {
		this.svnBrowser = svnBrowser;
	}

	public List<SbeSVNDiffItemView> getModifiedItems(String branchName, List<String> repositories){

		return getModifiedItems(branchName, repositories, "trunk");
	}

	public List<SbeSVNDiffItemView> getModifiedItems(String branchName, List<String> repositories, String repository){
		List<SbeSVNDiffItemView> result = new ArrayList<SbeSVNDiffItemView>();
		for (String selectedRepository : repositories) {
			String urlTrunk = ApplicationsConfig.getInstance().getRepositoryURL(selectedRepository).concat(repository);
			String urlBranch = ApplicationsConfig.getInstance().getRepositoryURL(selectedRepository).concat("branches/").concat(branchName);
			try {
				result.addAll(svnBrowser.getDiffListItems("hudson", "hudsonadmin", urlTrunk, urlBranch));
			} catch (SbeSvnException e) {
				e.printStackTrace();
			}
		}

		return result;
	}


}
